/*
 * @Author: your name
 * @Date: 2022-03-26 22:17:37
 * @LastEditTime: 2022-03-27 23:08:54
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \drivingTow\src\practice\practice.controller.ts
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { PracticeService } from './practice.service';
import { CreatePracticeDto } from './dto/create-practice.dto';
import { CancelProcticeDto, getMenegerPracticeDto, selectAllPraticeDto, selectPraticeDto, UpdatePracticeDto } from './dto/update-practice.dto';
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { RolesGuard } from 'src/auth/role.guard';
import { GetTimeDto } from './dto/getTime-practice.dto';

@ApiTags('约练车服务')
@Controller('practice')
export class PracticeController {
  constructor(private readonly practiceService: PracticeService) {}
  @ApiOperation({ summary: '创建教练练车表' })
  @ApiBearerAuth()
  @Post('creatPractice')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async create(@Body() post:CreatePracticeDto,@Req() req){
    return await this.practiceService.createCoach(post,req.user)
  }

  @ApiOperation({ summary: '学员约练车' })
  @ApiBearerAuth()
  @Post('updataPractice')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async updataPractice(@Body() post:UpdatePracticeDto,@Req() req){
    const newPost = {
      ...post,
      userId:req.user.id
    }
    return await this.practiceService.updataPractice(newPost)
  }

  @ApiOperation({ summary: '查看教练各个时间段还有多少位置' })
  @ApiBearerAuth()
  @Post('getAnyTime')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getAnyTime(@Body() post:GetTimeDto){
    return this.practiceService.getAnyTime(post)
  }

  @ApiOperation({ summary: '教练员查看今日练车表' })
  @ApiBearerAuth()
  @Post('getTheDay')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getTheDay(@Body() post:selectPraticeDto,@Req() req){
    const newPost = {
      ...post,
      userId:req.user.id
    }
    return this.practiceService.getTheDay(newPost)
  }

  @ApiOperation({ summary: '教练员查看全部练车表' })
  @ApiBearerAuth()
  @Post('getAllPractice')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getAllPractice(@Body() post:selectAllPraticeDto,@Req() req){
    const newPost = {
      ...post,
      userId:req.user.id
    }
    return this.practiceService.getAllPractice(newPost)
  }

  @ApiOperation({ summary: '管理员查看全部练车表' })
  @ApiBearerAuth()
  @Post('getMenegerPractice')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getMenegerPractice(@Body() post:getMenegerPracticeDto){
    return this.practiceService.getMenegerPractice(post)
  }

  @ApiOperation({ summary: '取消约车' })
  @ApiBearerAuth()
  @Post('CancelProctice')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async CancelProctice(@Body() post:CancelProcticeDto,@Req() req){
    const newPost = {
      ...post,
      userId:req.user.id
    }
    return this.practiceService.CancelProctice(newPost) 
  }

  @ApiOperation({ summary: '根据ID去查找练车表' })
  @ApiBearerAuth()
  @ApiParam({name:'id',description:'id'})
  @Get('findPracticeById:id')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async findPracticeById(@Param('id') id){
    return this.practiceService.findPracticeById(id)
  }
}
